{{>header}}
{{#pubLibrary}}library {{{.}}};{{/pubLibrary}}{{^pubLibrary}}library {{{pubName}}}.api;{{/pubLibrary}}

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart';
import 'package:intl/intl.dart';
import 'package:meta/meta.dart';

part 'api_client.dart';
part 'api_helper.dart';
part 'api_exception.dart';
part 'auth/authentication.dart';
part 'auth/api_key_auth.dart';
part 'auth/oauth.dart';
part 'auth/wrapper.dart';
part 'auth/http_basic_auth.dart';
part 'auth/http_bearer_auth.dart';

{{#apiInfo}}
{{#apis}}
part 'api/{{{classFilename}}}.dart';
part 'api/{{{classFilename}}}_generated.dart';

{{/apis}}
{{/apiInfo}}
{{#models}}{{#model}}part 'model/{{{classFilename}}}.dart';
{{/model}}{{/models}}

const _delimiters = {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'};
const _dateEpochMarker = 'epoch';
final _dateFormatter = DateFormat('yyyy-MM-dd');
final _regList = RegExp(r'^List<(.*)>$');
final _regSet = RegExp(r'^Set<(.*)>$');
final _regMap = RegExp(r'^Map<String,(.*)>$');

ApiClient defaultApiClient = ApiClient();

/**
 * Top-level client that provides access to the API classes. Instantiates its own ApiClient class and *Api classes.
 */
class {{clientName}} {
  late ApiClient apiClient;
  {{#apiInfo}}{{#apis}}late {{classname}} {{classNameCamelCase}};
  {{/apis}}{{/apiInfo}}
  // accepts a base path, creates an ApiClient instance and instantiates *Api classes
  {{clientName}}({
    String? basePath,
    {{#authMethods}}required String {{keyParamNamePascalCase}},
    {{/authMethods}}
  }) {
    List<Authentication> authentications = [];
    {{#authMethods}}
    {{#isApiKey}}
    authentications.add(ApiKeyAuth("{{apiKeyIn}}", "{{keyParamName}}", {{keyParamNamePascalCase}}));
    {{/isApiKey}}
    {{/authMethods}}
    Wrapper wrapper = Wrapper(authentications);
    apiClient = ApiClient(
        basePath: basePath ?? "{{{basePath}}}",
        authentication: wrapper);
    {{#apiInfo}}{{#apis}}{{classNameCamelCase}} = {{classname}}(apiClient);
    {{/apis}}{{/apiInfo}}
  }
}